<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let arr = [];
        function main(){
            alert('欢迎来到学员信息管理中心！');
            let flag = 1;
            while(flag){
                let num = +prompt(`请输入您的选项:\n1.新增学员\n2.删除学员\n3.显示学员列表\n4.退出`);
                switch(num){
                    case 1:
                        addStu();
                        break;
                    case 2: 
                        delStu();
                        break;
                    case 3: 
                        showStu();
                        break;
                    case 4: 
                        flag = null;
                        break;
                    default:
                        alert('请输入正确的选项！');
                }
            }
        }
        //调用main方法
        main();
        //构造函数
        function Stu(uname,age,sex){
            this.uname = uname;
            this.age = age;
            this.sex = sex;
        }
        //判断是否为数字
        function isAge(){
            let age = prompt('请输入年龄，必须为数字哟');
            while(isNaN(age)){
                age = prompt('年龄必须为数字，请重新输入！');
            }
            return age;
        }
        //新增学员函数
        function addStu(){
            let uname = prompt('请输入新增学员姓名');
            let age = isAge();
            let sex = prompt('请输入新增学员性别！');
            let obj = new Stu(umame,age,sex);
            arr.push(obj);
            if(!confirm(`新增学员【${uname}】成功!是否显示学员列表?`)) return;
            showStu();
        }
        //显示学员函数
        function showStu(){
            let str = '';
            for(let i = 0; i < arr.length; i++){
                str += arr[i].i
            }
        }
    </script>
</body>
</html>